import com.sun.org.apache.bcel.internal.generic.NEW;

import java.io.*;
import java.util.ArrayList;
import java.util.Iterator;

/**
 * @version v1.0
 * @Description
 * @Author admin
 * @date 2021/7/22  16:37
 * @Copyright
 */
public class zuoye01 {
    public static void main(String[] args) {
        //输入加入文件
        zuoye1();



        //输入加入集合
        zuoye2();








    }

    private static void zuoye2() {
        try (
                BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
                BufferedWriter bufferedWriter = new BufferedWriter(new OutputStreamWriter(System.out))

        ) {

            ArrayList<String> list = new ArrayList<>();
            String a = null;
            System.out.println("请输入姓名：");
            while ((a = reader.readLine()) != null) {
                list.add(a);
//                bufferedWriter.newLine();
//                bufferedWriter.flush();
                Iterator<String> iterator = list.iterator();

                while (iterator.hasNext()){
                      String next = iterator.next();
                     System.out.println("姓名 = " + next);

                 }
                System.out.println("是否继续：是/否");
                String s = reader.readLine();
                if (s.equals("是")){
                    System.out.println("请输入姓名：");
                    continue;
                }else {
                    break;
                }
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }


    private static void zuoye1() {
        try (
                BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
                 BufferedWriter writer = new BufferedWriter(new FileWriter("test.txt", true));
        ) {
            String a = " ";
            while ((a = reader.readLine()) != null) {
                writer.write(a);
                writer.flush();

            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
